package com.myblog.mapper;

import com.myblog.model.Leave;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;

import java.util.List;

@Mapper
public interface LeaveMapper {

    @Select("select * from leave_message_record order by id desc")
    List<Leave> selectAllLeaveWord();

    @Select("select count(*) from leave_message_record")
    Integer selectNumOfLeaveWord();

    @Select("select * from leave_message_record where pageName = #{pageName} order by id desc")
    List<Leave> selectLeaveWordByPageName(String pageName);

    void addLeaveWord(Leave leave);

    @Select("select count(*) from leave_message_record where respondentId = #{respondentId} and isRead = 1")
    Integer selectNotReadNumByRespondentId(@Param(value = "respondentId") Integer userId);

    @Select("select * from leave_message_record where respondentId = #{respondentId} order by id desc")
    List<Leave> selectLeaveWordByRespondentId(@Param(value = "respondentId") Integer userId);

    @Update("update leave_message_record set isRead = 0 where respondentId = #{respondentId} and isRead = 1")
    void updateAllLeaveIsReadByRespondentId(Integer respondentId);

    @Update("update leave_message_record set likes = likes+1 where id = #{id}")
    void updateLikeById(@Param(value = "id") Integer leaveId);

    @Select(("select likes from leave_message_record where id = #{id};"))
    int queryLikesById(@Param(value = "id") Integer leaveId);
}
